package com.atom.base;

import com.atom.annotation.ApiImpl;
import com.atom.annotation.api.ApiImplProvider;
import com.atom.annotation.bean.ApiImplWrapper;

public class ApiImplUtils {

    static class ApiImplPacket {
        public final Class<?> apiClass;
        public final Class<?> implClass;
        public final Class<? extends ApiImplProvider> provider;
        public final String name;
        public final long version;

        public ApiImplPacket(Class<?> apiClass, Class<?> implClass, Class<? extends ApiImplProvider> provider, String name, long version) {
            this.apiClass = apiClass;
            this.implClass = implClass;
            this.provider = provider;
            this.name = name;
            this.version = version;
        }

        @Override
        public String toString() {
            return "ApiImplPacket{" +
                    "apiClass=" + apiClass +
                    ", implClass=" + implClass +
                    ", provider=" + provider +
                    ", name='" + name + '\'' +
                    ", version=" + version +
                    '}';
        }
    }

    public static ApiImplPacket get(Class<?> clazz) {
        ApiImpl annotation = clazz.getAnnotation(ApiImpl.class);
        return new ApiImplPacket(annotation.api(), clazz, annotation.provider(), annotation.name(), annotation.version());
    }

}
